package m.ai.lab;

import org.opencv.core.Core;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**
 * 测试
 * 
 * @author liuhao
 */
public class Demo {
	public static void main(String[] args) throws Exception {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		Segmentation segmentor = new Segmentation();
		/**
		 * 输入基于opencv Mat作为参数,前端如果是视频流或者java bufferedImage请转换成openCV Mat
		 */
		SegmentationResult result = segmentor.predict(Imgcodecs.imread("images/4.jpg"));
		Size size = result.raw.size();
		Size scale = new Size(size.width / 2, size.height / 2);
		/**
		 * 图片缩小一半方便观看
		 */
		Imgproc.resize(result.raw, result.raw, scale);
		Imgproc.resize(result.mask, result.mask, scale);
		Imgproc.resize(result.result, result.result, scale);

		HighGui.imshow("原图", result.raw);
		HighGui.imshow("掩码", result.mask);
		HighGui.imshow("最终", result.result);

		HighGui.waitKey(0);
		HighGui.destroyAllWindows();
	}
}
